﻿#region Copyright
// Copyright (c) 2011-2012 RaisingForce Team (Alikin Sergey)
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion

using System;
using System.Diagnostics.Contracts;
using System.Xml.Serialization;

namespace RaisingForce.Raise.Language.Model.Rules
{
    [Serializable]
    [XmlType(TypeName = "Rule")]
    sealed public class RuleData
    {
        #region Constructors

        public RuleData()
        {
            this.ifWordData = WordData.CreateDefaultIfWordData();
            this.thenWordData = WordData.CreateDefaultThenWordData();
            this.chainWordData = WordData.CreateDefaultChainWordData();
        }

        public RuleData(
            WordData ifWordData,
            WordData thenWordData,
            WordData chainWordData)
        {
            if (ifWordData == null)
            {
                throw new ArgumentNullException("ifWordData");
            }
            if (thenWordData == null)
            {
                throw new ArgumentNullException("thenWordData");
            }
            if (chainWordData == null)
            {
                throw new ArgumentNullException("chainWordData");
            }
            Contract.EndContractBlock();
            this.ifWordData = ifWordData;
            this.thenWordData = thenWordData;
            this.chainWordData = chainWordData;
        }

        #endregion

        #region Private Declarations

        private WordData ifWordData;

        private WordData thenWordData;

        private WordData chainWordData;

        [ContractInvariantMethod]
        private void ObjectInvariant()
        {
            Contract.Invariant(this.ifWordData != null);
            Contract.Invariant(this.thenWordData != null);
            Contract.Invariant(this.chainWordData != null);
        }

        #endregion

        #region Properties

        [XmlElement(ElementName = "If")]
        public WordData IfWordData
        {
            get
            {
                Contract.Ensures(Contract.Result<WordData>() != null);
                return this.ifWordData;
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("IfWordData");
                }
                Contract.EndContractBlock();
                this.ifWordData = value;
            }
        }

        [XmlElement(ElementName = "Then")]
        public WordData ThenWordData
        {
            get
            {
                Contract.Ensures(Contract.Result<WordData>() != null);
                return this.thenWordData;
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("ThenWordData");
                }
                Contract.EndContractBlock();
                this.thenWordData = value;
            }
        }

        [XmlElement(ElementName = "Chain")]
        public WordData ChainWordData
        {
            get
            {
                Contract.Ensures(Contract.Result<WordData>() != null);
                return this.chainWordData;
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("ChainWordData");
                }
                Contract.EndContractBlock();
                this.chainWordData = value;
            }
        }

        #endregion
    }
}
